package org.example.ymcc.controller;

import org.example.ymcc.domain.dto.ValidImgCodeDto;
import org.example.ymcc.result.JsonResult;
import org.example.ymcc.service.ImgCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/common/imgCode")
public class ImgCodeController {
    @Autowired
    private ImgCodeService imgCodeService;

    @GetMapping("/{key}")
    public JsonResult createImgCode(@PathVariable("key")String key){
        String imgCode = imgCodeService.createImgCode(key);
        return JsonResult.success().setData(imgCode);
    }

    @PostMapping("/valid")
    public JsonResult validImgCode(@Valid @RequestBody ValidImgCodeDto imgCodeDto){
        return imgCodeService.validImgCode(imgCodeDto);
    }
}
